﻿Public Class ParteEnfermeria
    Inherits System.Web.UI.Page
    Shared Paciente As New Persona
    Shared Enfermero As New Persona
    Shared ID_cabecera As Integer



    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim ImagFondo As Image = Page.Master.FindControl("ImagFondoCabecera")

        If Not Page.IsPostBack Then

            Enfermero = PersLOgueada

            ImagFondo.Height = 500

        End If

    End Sub
    Private Sub lImpia_campos_DelEnfermero()

        txtReport.Text = ""
        txtPA.Text = ""
        txtFC.Text = ""
        txtFR.Text = ""
        txtTemperatura.Text = ""
        txtDuiresis.Text = ""
        txtCatarsis.Text = ""


    End Sub
    Private Sub limpiaCampos_DATOSpERSONA()

        FG.SacaCartelDeAViso(lblMsjeDeBuscar)
        FG.SacaCartelDeAViso(lblMsjeGuardar)




        txtdni_paciente.Text = ""
        txtUltimoImforme.Text = ""
        txtNombrePaciente.Text = ""
        txtApellidoPaciente.Text = ""
        txtMotivo.Text = ""
        txtDiagnostico.Text = ""
        txtUltimaIndicacionMedica.Text = ""
        txtMedicameto.Text = ""


    End Sub
    Private Function TraeUltimoReporte() As String
        Dim param(1) As ADODB.Parameter
        Dim Rs As ADODB.Recordset




        param(0) = New ADODB.Parameter
        param(0).Name = "@dni"
        param(0).Type = ADODB.DataTypeEnum.adVarChar
        param(0).Direction = ADODB.ParameterDirectionEnum.adParamInput
        param(0).Value = Paciente.Dev_Dni
        param(0).Size = 10


        param(1) = New ADODB.Parameter
        param(1).Name = "@id_institucion"
        param(1).Type = ADODB.DataTypeEnum.adInteger
        param(1).Direction = ADODB.ParameterDirectionEnum.adParamInput
        param(1).Value = Enfermero.Dev_ID_Institucion
        'param(1).Size = 10



        Rs = Datos.TraerTodos("traeUltimoReporteDeEnfermeriaxDni", param, "TraeUltimoReporte - Parteenfermeria")

        TraeUltimoReporte = Rs.Fields(0).Value.ToString


    End Function
    Private Sub MuestraDatosParaEnfermero()
        Dim param(0) As ADODB.Parameter
        Dim Rs As ADODB.Recordset



        txtdni_paciente.Text = Paciente.Dev_Dni

        txtNombrePaciente.Text = Paciente.Dev_Nombre
        txtApellidoPaciente.Text = Paciente.Dev_apellido

        ' funcionque trae el ultimo fecha reporte del enfermero en esa clinica 
        txtUltimoImforme.Text = TraeUltimoReporte()

        '..............

        'voy a busar los ultimos datos del paciente cn estado internado
        param(0) = New ADODB.Parameter
        param(0).Name = "@dni"
        param(0).Type = ADODB.DataTypeEnum.adVarChar
        param(0).Direction = ADODB.ParameterDirectionEnum.adParamInput
        param(0).Value = Paciente.Dev_Dni
        param(0).Size = 10

        Rs = Datos.TraerTodos("buscaDatosdelPAcienteParaEnfermero", param, "MuestraDatosParaEnfermero - parte Enfermeria")

        txtMotivo.Text = Rs.Fields(0).Value.ToString
        txtDiagnostico.Text = Rs.Fields(1).Value.ToString
        txtUltimaIndicacionMedica.Text = Rs.Fields(2).Value.ToString
        txtMedicameto.Text = Rs.Fields(3).Value.ToString

        'el id de cabecera_hc
        ID_cabecera = CInt(Rs.Fields(4).Value)

    End Sub

    Protected Sub btnBuscar_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnBuscar.Click
        limpiaCampos_DATOSpERSONA()
        lImpia_campos_DelEnfermero()

        'validacio n
        If txtDNI.Text = "Búsqueda DNI" Or txtDNI.Text = "" Then
            FG.MuestraCartel("Debe ingresar un dni", lblMsjeDeBuscar)
            Exit Sub
        End If


        'seteo los datos 
        Paciente.SetaDatosXDn(txtDNI.Text)

        If Paciente.Dev_ExistePersona = False Then
            FG.MuestraCartel("El Dni no existe", lblMsjeDeBuscar)
            Exit Sub
        End If

        If Paciente.Dev_EstaInternado = False Then
            FG.MuestraCartel("la persona no se encuentra Internada", lblMsjeDeBuscar)
            Exit Sub
        End If

        If Paciente.Dev_EstaMurido = True Then
            FG.MuestraCartel("la persona ha fallecido, no se puede agregar informacion", lblMsjeDeBuscar)
            Exit Sub
        End If
        '----------------


        MuestraDatosParaEnfermero()


    End Sub

    Private Function GUardarReporteEnfermero(ByVal _signoVItales As String) As Boolean
        Dim param(2) As ADODB.Parameter

        param(0) = New ADODB.Parameter
        param(0).Name = "@_IDcabecera"
        param(0).Type = ADODB.DataTypeEnum.adInteger
        param(0).Direction = ADODB.ParameterDirectionEnum.adParamInput
        param(0).Value = ID_cabecera
        'param(0).Size = 10


        param(1) = New ADODB.Parameter
        param(1).Name = "@Report"
        param(1).Type = ADODB.DataTypeEnum.adVarChar
        param(1).Direction = ADODB.ParameterDirectionEnum.adParamInput
        param(1).Value = txtReport.Text
        param(1).Size = 8000

        param(2) = New ADODB.Parameter
        param(2).Name = "@signoViatles"
        param(2).Type = ADODB.DataTypeEnum.adVarChar
        param(2).Direction = ADODB.ParameterDirectionEnum.adParamInput
        param(2).Value = _signoVItales
        param(2).Size = 3000

     

        GUardarReporteEnfermero = Datos.Agregar("cargaReporteEnfermeria", param, "GUardarReporteEnfermero -parteenfermeria")





    End Function


    Protected Sub btnGuardar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnGuardar.Click
        Dim SigNosVitales As String

        If txtReport.Text = "" Then
            FG.MuestraCartel("Debe escribir el report", lblMsjeGuardar)
            Exit Sub
        End If

        SigNosVitales = IIf(txtPA.Text <> "", "P.A.:" & txtPA.Text & " | ", "")
        SigNosVitales = SigNosVitales & IIf(txtFC.Text <> "", "F.C.:" & txtFC.Text & " | ", "")
        SigNosVitales = SigNosVitales & IIf(txtFR.Text <> "", "F.R.:" & txtFR.Text & " | ", "")
        SigNosVitales = SigNosVitales & IIf(txtTemperatura.Text <> "", "T.:" & txtTemperatura.Text & " | ", "")
        SigNosVitales = SigNosVitales & IIf(txtDuiresis.Text <> "", "Dur.:" & txtDuiresis.Text & " | ", "")
        SigNosVitales = SigNosVitales & IIf(txtCatarsis.Text <> "", "catar.:" & txtCatarsis.Text, "")



        If GUardarReporteEnfermero(SigNosVitales) = True Then
            limpiaCampos_DATOSpERSONA()
            lImpia_campos_DelEnfermero()

            FG.MuestraCartel("se cargo correctamente el reporte", lblMsjeGuardar)

        Else
            FG.MuestraCartel("Se Produjo un error al guardar", lblMsjeGuardar)

        End If


    End Sub
End Class